﻿using MapHello.Basic;
using MapHello.Service.Live;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MapHello.Core
{
    class LoadLivePersonTask : AsyncTask
    {
        public event LoadPersonDelegate OnTaskCompleted;

        public override void Run(object state)
        {
            LoadPersonContext context = state as LoadPersonContext;

            bool isMe = string.IsNullOrEmpty(context.PersonId);

            var person = LiveService.LoadPerson(context.Token, context.PersonId);
            this.Args = new LoadLivePersonArgs()
            {
                Person = person.Result,
                IsMe = isMe
            };
        }

        protected override void ProtectedNotifyCompletion()
        {
            if (null != OnTaskCompleted)
            {
                OnTaskCompleted(this.Args as LoadLivePersonArgs);
            }
        }
    }
}
